<template>
    <div class="select-wrapper">
        <div class="list-container">
            <div class="list">
                <div class="item"
                     v-for="(item, index) in num"
                     :key="index"
                     @click="toggleActive(item)">
                    <div class="item-item"
                         :class="[activeNum == item ? 'item-active' : '']">{{item}}
                    </div>
                </div>
            </div>
        </div>
        <div class="sure">
            <span @click="sureSelect"> 确定选择 </span>
        </div>
        <mt-popup
                v-model="popup.isVisible"
                :closeOnClickModal="false"
                popup-transition="popup-fade">
            <div class="more-num">
                <div class="header">填写用餐人数<span class="close" @click="popup.isVisible = false"></span></div>
                <div class="body">
                    <input v-model="moreNum">
                </div>
                <div class="foot">
                    <div class="item" @click="popup.isVisible = false">确认</div>
                </div>
            </div>
        </mt-popup>
    </div>
</template>
<script>
    import {Toast} from 'mint-ui';
    export default {
        async asyncData ({req}) {
            return {
                store: req.query.store,
                table: req.query.table,
            }
        },
        data(){
            return {
                num: [1, 2, 3, 4, 5, 6, 7, 8, '更多'],
                activeNum: '',
                moreNum: '',
                popup: {
                    isVisible: false
                }
            }
        },
        head () {
            return {
                title: '请选择就餐人数',
            }
        },
        methods: {
            toggleActive(item){
                this.activeNum = item;
                if (item != '更多') {
                    this.moreNum = ''
                } else {
                    this.popup.isVisible = true
                }
            },
            sureSelect(){
                if (this.activeNum) {
                    if (this.activeNum == '更多' && !this.moreNum) {
                        Toast('请选择就餐人数')
                    } else if(this.activeNum == '更多' && this.moreNum) {
                        window.location.href = `/menu?store=${this.store}&table=${this.table}&num=${this.moreNum}`
                    }else {
                        window.location.href = `/menu?store=${this.store}&table=${this.table}&num=${this.activeNum}`
                    }

                } else {
                    Toast('请选择就餐人数')
                }
            },
        }
    }
</script>
<style lang="less" scoped>
    .select-wrapper {
        display: flex;
        flex-direction: column;
        min-height: 100vh;
        justify-content: center;
        padding-bottom: 20px;
        .list-container {
            display: flex;
            justify-content: center;
            width: 80%;
            margin: 0 10%;

        }
        .list {
            display: flex;
            justify-content: space-between;
            flex-wrap: wrap;
            padding: 48px 0 28px 0;
            width: 100%;
            .item {
                width: 33%;
                height: 60px;
                margin-bottom: 20px;
                display: flex;
                justify-content: center;
                align-items: center;
                .item-item {
                    background: #FFFFFF;
                    box-shadow: 0 2px 10px 0 rgba(0, 0, 0, 0.10);
                    border-radius: 50%;
                    line-height: 60px;
                    width: 60px;
                    text-align: center;
                    font-size: 18px;
                    cursor: pointer;
                }
                .item-active {
                    background-image: linear-gradient(-38deg, #FFEB00 3%, #FFD200 60%);
                    box-shadow: 0 2px 10px 0 rgba(0, 0, 0, 0.10);
                }
            }

        }
        .sure {
            width: 80%;
            text-align: center;
            margin: 0 10%;
            height: 44px;
            background: #000000;
            box-shadow: 0 4px 10px 0 rgba(0, 0, 0, 0.20);
            border-radius: 21px;
            font-size: 18px;
            color: #FFFFFF;
            letter-spacing: 0.22px;
            line-height: 44px;
        }
        span {
            text-decoration: none;
            display: inline-block;
            width: 100%;
            color: #FFFFFF;
        }
        .more-num {
            width: 295px;
            background: #FFFFFF;
            box-shadow: 0 2px 10px 0 rgba(0, 0, 0, 0.10);
            border-radius: 8px;
            display: flex;
            flex-direction: column;
            .header {
                height: 45px;
                line-height: 45px;
                border-bottom: 1px solid #EDEDED;
                font-size: 18px;
                color: #000000;
                letter-spacing: 0.22px;
                text-align: center;
                position: relative;
                .close {
                    position: absolute;
                    display: block;
                    width: 36px;
                    height: 36px;
                    top: -18px;
                    right: -18px;
                    border-radius: 50%;
                    background: #fff url(../components/common/img/x@1x.png) no-repeat center;
                }
            }
            .body {
                flex: 1;
                padding: 20px;
                input {
                    border: 1px solid #eee;
                    width: 100%;
                    height: 50px;
                    border-radius: 4px;
                    padding: 0 10px;

                }
            }
            .foot {
                height: 65px;
                line-height: 65px;
                text-align: center;
                background: #FFFFFF;
                box-shadow: 0 -2px 10px 0 rgba(0, 0, 0, 0.10);
                display: flex;
                border-radius: 5px;
                .item {
                    flex: 1;
                    background: #000000;
                    font-size: 18px;
                    color: #FFFFFF;
                }
            }
        }
    }
</style>